/**
 * Copyright (c) 2013 Axa Holding Belgium, SA. All rights reserved.
 * This software is the confidential and proprietary information of the AXA Group.
 */
package chabernac.android.chargemybattery.actions;

import android.bluetooth.BluetoothAdapter;
import android.content.Context;

public class TurnOffBlueToothAction extends AbstractPowerSaveAction {
    private final BluetoothAdapter bluetoothAdapter;
    private boolean                isBluetoothEnabled;

    public TurnOffBlueToothAction( Context aContext ) {
        bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    }

    @Override
    public void executeAction() {
        isBluetoothEnabled = bluetoothAdapter.isEnabled();
        bluetoothAdapter.disable();
    }

    @Override
    public void undo() {
        if ( isBluetoothEnabled ) {
            bluetoothAdapter.enable();
        }

    }

    @Override
    public boolean isComplete() {
        return !bluetoothAdapter.isEnabled();
    }

}
